package com.example.spring5.designmode.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: Hu Rui
 * @Date: 2021/11/12 14:01
 */
public class Observerable {
    private int state;
    private static final List<Observer> observers = new ArrayList<>();

    public void add(Observer observer) {
        observers.add(observer);
    }

    public void remove(Observer observer) {
        observers.remove(observer);
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public void notifyObservers(int state, String message) {
        if (state == 1) {
            for (Observer observer : observers) {
                observer.doEvent(message);
            }
        }
    }

}
